package com.example.cloud.provider.payment.controller;

import com.example.cloud.entities.entity.Payment;
import com.example.cloud.provider.payment.service.IPaymentService;
import com.example.cloud.entities.utils.PageQuery;
import com.example.cloud.entities.utils.SimpleMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 *  内部接口
 * </p>
 *
 * @author frank
 * @since 2020-10-18
 */
@Api(tags = " 内部接口")
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    public IPaymentService paymentService;

    /**
    * 新增
    *
    * @param payment
    * @return
    */
    @ApiOperation("新增")
    @RequestMapping(method = RequestMethod.POST)
    public SimpleMessage<Payment> save(@RequestBody Payment payment){
        boolean save = paymentService.save(payment);
        if(save){
            return SimpleMessage.info("添加成功 ");
        }else{
            return SimpleMessage.fail("添加失败");
        }
    }

    /**
    * 修改
    *
    * @param payment
    * @return
    */
    @ApiOperation("修改")
    @RequestMapping(method = RequestMethod.PUT)
    public SimpleMessage<Payment> update(@RequestBody Payment payment) {
        boolean save = paymentService.updateById(payment);
        if (save) {
            return SimpleMessage.info("修改成功");
        } else {
            return SimpleMessage.fail("修改失败");
        }
    }

    /**
    * 删除
    *
    * @param id 主键id
    * @return
    */
    @ApiOperation("删除")
    @RequestMapping(value = "/{id}" , method = RequestMethod.DELETE)
    public SimpleMessage delete(@PathVariable int id) {
        return paymentService.deleteById(id);
    }

    /**
    * 查询详情
    *
    * @param id 主键id
    * @return
    */
    @ApiOperation("查询详情")
    @RequestMapping(value = "/{id}" , method = RequestMethod.GET)
    public SimpleMessage<Payment> findOne(@PathVariable long id) {
        return SimpleMessage.info(paymentService.getById(id));
    }

    /**
    * 分页查询
    *
    * @param pageQuery 分页查询
    * @return
    */
    @ApiOperation("分页查询")
    @RequestMapping(method = RequestMethod.GET)
    public SimpleMessage queryByPage(PageQuery pageQuery) {
        return paymentService.queryByPage(pageQuery);
    }
}
